package com.jmb.apiplatform.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

import static com.jmb.apiplatform.constant.Constants.EXPIRE;
import static com.jmb.apiplatform.constant.Constants.SIGNIFY;


@Component
public class JwtUtils {

    @Autowired
    private RedisUtil redisUtil;

    public  String generateJwt(Map<String,Object> claims){
        String jwt = Jwts.builder()
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS256, SIGNIFY)
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRE))
                .compact();
        return jwt;
    }
    public  Claims parseJWT(String jwt){
        Claims claims = Jwts.parser()
                .setSigningKey(SIGNIFY)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }

}
